package com.junit.test.hessian.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.caucho.hessian.client.HessianConnection;
import com.caucho.hessian.client.HessianConnectionFactory;
import com.caucho.hessian.client.HessianProxyFactory;
import com.caucho.hessian.client.HessianURLConnectionFactory;

public class HessianClient {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	static final Log logger = LogFactory.getLog(HessianClient.class);
	@Test
	public void test() throws MalformedURLException, IOException, ClassNotFoundException {
		String url = "http://hessian.caucho.com/test/test";
        String yahoo_url = "http://weather.yahooapis.com/forecastrss";
		HessianConnectionFactory connectionFactory = new HessianURLConnectionFactory();
		HessianProxyFactory proxyFactory = new HessianProxyFactory();
		//proxyFactory.create(yahoo_url);
		connectionFactory.setHessianProxyFactory(proxyFactory);
		HessianConnection connection = connectionFactory.open(new URL("http://weather.yahooapis.com/forecastrss"));
		logger.info(connection.getStatusMessage());
		logger.info(connection.getStatusCode());
        InputStream is =  connection.getInputStream();
        InputStreamReader isr = new InputStreamReader(is, "utf-8");
        BufferedReader br = new BufferedReader(isr);
        String s;
        while((s = br.readLine()) != null){
        	logger.info(s);
        }
	}

}
